package com.reuters.rfa.example.omm.gui.viewer;


import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.logging.Level;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;
import javax.swing.KeyStroke;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author nitin.parmar
 */
public class AppOptions extends javax.swing.JDialog {
    
    /**
     * Creates new form AppOptions
     */
    public AppOptions(UserOptions userOps, java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        parentFrame = parent;
        userOptions = userOps;
        initComponents();
        dialogFontSize.setModel(fontSizeSpinModel);
        setDefaultActions();
    }

    private void setDefaultActions() {
        this.getRootPane().setDefaultButton(okButton);
        JRootPane rootPane = this.getRootPane();
        InputMap iMap = rootPane.getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        iMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");
        ActionMap aMap = rootPane.getActionMap();
        aMap.put(
                "escape", new
                AbstractAction()
                    {
                        public void actionPerformed(ActionEvent e)
                        {
                            cancelButtonActionPerformed(null);
                        }
                    }
                );
    }
    
    private void setCurrentValues() {
        if ( userOptions != null ) {
            applicationIdText.setText( userOptions.getAppId() );
            positionText.setText( userOptions.getPosition() );
            pauseAndResume.setSelected(userOptions.getSupportPauseResume());
            sortableColumns.setSelected(userOptions.getSortable());
            
            if (userOptions.getDownloadDicts() == true) {
                downloadDict.setSelected(true);
                rdmFieldDictLabel.setEnabled(false);
                rdmFieldDictText.setEnabled(false);
                rdmFieldDictText.setText("");
                rdmDictSearchButton.setEnabled(false);
                enumDictLabel.setEnabled(false);
                enumDictText.setEnabled(false);
                enumDictText.setText("");
                enumDictSearchButton.setEnabled(false);
            }
            else {
                downloadDict.setSelected(false);
                rdmFieldDictLabel.setEnabled(true);
                rdmFieldDictText.setEnabled(true);
                rdmFieldDictText.setText(userOptions.getRdmFieldDict());
                rdmDictSearchButton.setEnabled(true);
                enumDictLabel.setEnabled(true);
                enumDictText.setEnabled(true);
                enumDictText.setText(userOptions.getEnumTablesDict());
                enumDictSearchButton.setEnabled(true);
            }
            
            dialogFont.setSelectedItem(userOptions.getDialogFont());
            dialogFontSize.setValue(userOptions.getDialogFontSize());

            logLevel = userOptions.getLogLevel();
            if (logLevel == Level.OFF) javaLogLevel.setSelectedIndex(1);
            else if (logLevel == Level.SEVERE) javaLogLevel.setSelectedIndex(2);
            else if (logLevel == Level.WARNING) javaLogLevel.setSelectedIndex(3);
            else if (logLevel == Level.INFO) javaLogLevel.setSelectedIndex(4);
            else if (logLevel == Level.CONFIG) javaLogLevel.setSelectedIndex(5);
            else if (logLevel == Level.FINE) javaLogLevel.setSelectedIndex(6);
            else if (logLevel == Level.FINER) javaLogLevel.setSelectedIndex(7);
            else if (logLevel == Level.FINEST) javaLogLevel.setSelectedIndex(8);
            else if (logLevel == Level.ALL) javaLogLevel.setSelectedIndex(9);
            else javaLogLevel.setSelectedIndex(0);
        }      
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pauseAndResume = new javax.swing.JCheckBox();
        sortableColumns = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        positionText = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        applicationIdText = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        javaLogLevel = new javax.swing.JComboBox();
        traceOptionsButton = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        downloadDict = new javax.swing.JCheckBox();
        rdmFieldDictLabel = new javax.swing.JLabel();
        enumDictLabel = new javax.swing.JLabel();
        rdmFieldDictText = new javax.swing.JTextField();
        enumDictText = new javax.swing.JTextField();
        rdmDictSearchButton = new javax.swing.JButton();
        enumDictSearchButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        okButton = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        dialogFont = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        dialogFontSize = new javax.swing.JSpinner();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Application Options");
        setAlwaysOnTop(true);
        setModal(true);
        setResizable(false);

        pauseAndResume.setText("Request Pause & Resume Support");
        pauseAndResume.setToolTipText("Specifiy pause and resume support in the login to the server");
        pauseAndResume.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pauseAndResumeActionPerformed(evt);
            }
        });

        sortableColumns.setText("Sortable Columns");
        sortableColumns.setToolTipText("Allow displayed columns to be sorted. This option can affect the performance");

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel2.setText("Position");

        positionText.setToolTipText("Optional position value used for permissioning");

        jLabel1.setText("Applications Id");

        applicationIdText.setToolTipText("Optional application Id used for permissioning");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(applicationIdText, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(positionText, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(applicationIdText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(positionText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javaLogLevel.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Parent Level", "Off", "Severe", "Warning", "Info", "Config", "Fine", "Finer", "Finest", "All" }));
        javaLogLevel.setToolTipText("Java log level used by RFA and this application");

        traceOptionsButton.setText("RFA Trace Options");
        traceOptionsButton.setToolTipText("Set RFA trace options");
        traceOptionsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                traceOptionsButtonActionPerformed(evt);
            }
        });

        jLabel7.setText("Java Logging");
        jLabel7.setMaximumSize(null);
        jLabel7.setPreferredSize(null);
        jLabel7.setRequestFocusEnabled(false);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(javaLogLevel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(traceOptionsButton)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(traceOptionsButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(javaLogLevel))
                .addGap(10, 10, 10))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        downloadDict.setSelected(true);
        downloadDict.setText("Download Data Dictionary");
        downloadDict.setToolTipText("Download data dictionaries from the server");
        downloadDict.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                downloadDictActionPerformed(evt);
            }
        });

        rdmFieldDictLabel.setText("RDM Field Dictionary");

        enumDictLabel.setText("Enum Tables Dictionary");

        rdmFieldDictText.setToolTipText("Full path and filename of the RDM field dictionary");
        rdmFieldDictText.setEnabled(false);

        enumDictText.setToolTipText("Full path and filename of the enum tables dictionary");
        enumDictText.setEnabled(false);

        rdmDictSearchButton.setText("...");
        rdmDictSearchButton.setToolTipText("Search for the RDM field dictionary");
        rdmDictSearchButton.setEnabled(false);
        rdmDictSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdmDictSearchButtonActionPerformed(evt);
            }
        });

        enumDictSearchButton.setText("...");
        enumDictSearchButton.setToolTipText("Search for the enum tables dictionary");
        enumDictSearchButton.setEnabled(false);
        enumDictSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enumDictSearchButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(downloadDict)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(enumDictLabel)
                            .addComponent(rdmFieldDictLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(enumDictText)
                            .addComponent(rdmFieldDictText))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(enumDictSearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(rdmDictSearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(downloadDict)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rdmFieldDictLabel)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(rdmFieldDictText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(rdmDictSearchButton)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enumDictText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(enumDictLabel)
                    .addComponent(enumDictSearchButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel5.setText("Dialog Font");
        jLabel5.setMinimumSize(new java.awt.Dimension(69, 14));

        dialogFont.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Monospaced", "Dialog", "Dialog Input", "SanSerif", "Serif" }));
        dialogFont.setToolTipText("Font used by the application to display the data");
        dialogFont.setName(""); // NOI18N

        jLabel6.setText("Font Size");

        dialogFontSize.setToolTipText("Font size used by the application to display the data");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(dialogFont, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dialogFontSize, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dialogFont)
                    .addComponent(jLabel6)
                    .addComponent(dialogFontSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(okButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelButton))
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sortableColumns)
                            .addComponent(pauseAndResume))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pauseAndResume)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sortableColumns)
                .addGap(5, 5, 5)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(okButton)
                    .addComponent(cancelButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        entryOk = true;
        
        switch( javaLogLevel.getSelectedIndex() )
        {
            case 1:
                logLevel = Level.OFF;
                break;
            case 2:
                logLevel = Level.SEVERE;
                break;
            case 3:
                logLevel = Level.WARNING;
                break;
            case 4:
                logLevel = Level.INFO;
                break;
            case 5:
                logLevel = Level.CONFIG;
                break;
            case 6:
                logLevel = Level.FINE;
                break;
            case 7:
                logLevel = Level.FINER;
                break;
            case 8:
                logLevel = Level.FINEST;
                break;
            case 9:
                logLevel = Level.ALL;
                break;                   
            default:
                logLevel = null;
                break;
        }
        
        // if data dictionary download is not selected
        if (downloadDict.isSelected() == false) {
            // if the RDM field dictionary has not been specified
            if (rdmFieldDictText.getText().length() == 0) {
                JOptionPane.showMessageDialog(this,
                    "Full path and filename of the RDM field dictionary must be specified, if not downloading",
                    "Application Options Error",
                    JOptionPane.ERROR_MESSAGE);
                rdmFieldDictText.requestFocusInWindow();
                entryOk = false;
            }
            // else if the Enum Tabled dictionary has not been specified
            else if (enumDictText.getText().length() == 0) {
                JOptionPane.showMessageDialog(this,
                    "Full path and filename of the Enum tables dictionary must be specified, if not downloading",
                    "Application Options Error",
                    JOptionPane.ERROR_MESSAGE);
                enumDictText.requestFocusInWindow();
                entryOk = false;
            }
        }
        
        if (entryOk) {
            userOptions.storeAppOptionVals(
                    applicationIdText.getText(), 
                    positionText.getText(), 
                    pauseAndResume.isSelected(),
                    sortableColumns.isSelected(),
                    downloadDict.isSelected(),
                    rdmFieldDictText.getText(),
                    enumDictText.getText(),
                    dialogFont.getSelectedItem().toString(),
                    Integer.parseInt( dialogFontSize.getValue().toString() ),
                    logLevel
                    );
            
            this.setVisible(false);
            if ( traceOptions != null ) {
                traceOptions.dispose();
                traceOptions = null;
            }
        }
    }//GEN-LAST:event_okButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        entryOk = false;
        this.setVisible(false);
        if ( traceOptions != null ) {
            traceOptions.dispose();
            traceOptions = null;
        }
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void traceOptionsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_traceOptionsButtonActionPerformed
        if ( traceOptions == null)
        {
            traceOptions = new TraceOptions( userOptions, parentFrame, true );
        }
        traceOptions.getOptions();
    }//GEN-LAST:event_traceOptionsButtonActionPerformed

    private void rdmDictSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdmDictSearchButtonActionPerformed
        fileChooser.setDialogTitle("Select RDM Field Dictionary");    
        if ( (rdmFieldDictText.getText().length() == 0) && (enumDictText.getText().length() == 0) ){
            fileChooser.setCurrentDirectory(defaultDictDir);
        }
        else {
            fileChooser.setCurrentDirectory(new File(rdmFieldDictText.getText()));
        }
        
        int returnVal = fileChooser.showOpenDialog( this );
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            rdmFieldDictText.setText(fileChooser.getSelectedFile().getAbsolutePath());
        }
    }//GEN-LAST:event_rdmDictSearchButtonActionPerformed

    private void enumDictSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enumDictSearchButtonActionPerformed
        fileChooser.setDialogTitle("Select Enum Tables Dictionary");
        if ( (rdmFieldDictText.getText().length() == 0) && (enumDictText.getText().length() == 0) ){
            fileChooser.setCurrentDirectory(defaultDictDir);
        }
        else {
            fileChooser.setCurrentDirectory(new File(enumDictText.getText()));
        }
        
        int returnVal = fileChooser.showOpenDialog( this );
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            enumDictText.setText(fileChooser.getSelectedFile().getAbsolutePath());
        }
    }//GEN-LAST:event_enumDictSearchButtonActionPerformed

    private void downloadDictActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadDictActionPerformed
        boolean state = downloadDict.isSelected();
        rdmFieldDictLabel.setEnabled(!state);
        rdmFieldDictText.setEnabled(!state);
        rdmDictSearchButton.setEnabled(!state);
        enumDictLabel.setEnabled(!state);
        enumDictText.setEnabled(!state);
        enumDictSearchButton.setEnabled(!state);
    }//GEN-LAST:event_downloadDictActionPerformed

    private void pauseAndResumeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseAndResumeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_pauseAndResumeActionPerformed

    public boolean getOptions() {
        setCurrentValues();
        this.setLocationRelativeTo( parentFrame );
        this.setVisible(true);
        return entryOk;
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AppOptions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AppOptions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AppOptions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AppOptions.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                AppOptions dialog = new AppOptions(null, new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    private Frame parentFrame = null;
    private TraceOptions traceOptions = null;
    private File defaultDictDir = new File("/var/triarch");
    private JFileChooser fileChooser = new JFileChooser();
    private SpinnerModel fontSizeSpinModel = new SpinnerNumberModel(12, 8, 40, 1);
    private UserOptions userOptions = null;
    private Level logLevel = null;
    private boolean entryOk = false;

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField applicationIdText;
    private javax.swing.JButton cancelButton;
    private javax.swing.JComboBox dialogFont;
    private javax.swing.JSpinner dialogFontSize;
    private javax.swing.JCheckBox downloadDict;
    private javax.swing.JLabel enumDictLabel;
    private javax.swing.JButton enumDictSearchButton;
    private javax.swing.JTextField enumDictText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JComboBox javaLogLevel;
    private javax.swing.JButton okButton;
    private javax.swing.JCheckBox pauseAndResume;
    private javax.swing.JTextField positionText;
    private javax.swing.JButton rdmDictSearchButton;
    private javax.swing.JLabel rdmFieldDictLabel;
    private javax.swing.JTextField rdmFieldDictText;
    private javax.swing.JCheckBox sortableColumns;
    private javax.swing.JButton traceOptionsButton;
    // End of variables declaration//GEN-END:variables
}
